package com.lottery.service.pc28.statisticsService.impl;

import com.lottery.dao.pc28.statisticsDao.TotalMoneyDao;
import com.lottery.dto.ResultDto;
import com.lottery.entity.TotalMoney;
import com.lottery.service.pc28.statisticsService.TotalMoneyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;

@Service
public class TotalMoneyServiceImpl implements TotalMoneyService {

	@Resource
	private TotalMoneyDao totalMoneyDao;

	/**
	 * 插入数据
	 * 
	 * @param expect
	 *            期号
	 */

	public ResultDto<TotalMoney> insetTotalMoney(String expect) {
		ResultDto<TotalMoney> resultDto = new ResultDto<TotalMoney>();
		TotalMoney totalMoney = null;
		List<TotalMoney> list = totalMoneyDao.getTotalMoneyLimit(expect);
		if (list != null && list.size() > 0) {
			for (TotalMoney totalMoneyLimit : list) {
				totalMoney = new TotalMoney();
				// 中奖总金额
				double winTotalmoney = totalMoneyLimit.getWinTotalmoney();
				// 投注总金额
				double bettingmoney = totalMoneyLimit.getBettingmoney();
				// 收益
				double income = 0;
				double bettingmoney2 = totalMoneyDao.getBettingmoney(expect);
				double winningamount2 = totalMoneyDao.getWinningamount(expect);
				income = bettingmoney2 - winningamount2;
				DecimalFormat df = new DecimalFormat("#0.##");
				df.setRoundingMode(RoundingMode.FLOOR);
				income = Double.valueOf(df.format(income));
				totalMoney.setBettingmoney(bettingmoney);
				totalMoney.setWinTotalmoney(winTotalmoney);
				totalMoney.setTotalDate(new Date());
				totalMoney.setIncome(income);
				totalMoney.setExpect(expect);
				try {
					// 执行插入插入
					totalMoneyDao.insertTotalMoney(totalMoney);
					resultDto.setMessage("200");
					resultDto.setSuccess(true);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					resultDto.setMessage("400" + e.toString());
					resultDto.setSuccess(false);
					return resultDto;
				}
			}
		}

		return resultDto;
	}

}
